package com.hy.myapp.rest;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.hy.myapp.Entity.Emp;
import com.hy.myapp.mapper.ReputationMapper;

/**
 * 用于用户服务的Restful控制器
 * @author hy
 * 2021年11月7日
 */
@RestController
public class ReputationRestCtrl extends Pager{
	@Autowired
	private ReputationMapper rptnMapper;
	
	@RequestMapping(value="/pagedQueryRptn", method=RequestMethod.GET)
	public Map<String,Object> pagedQueryRptn(int pageNo,String keyword){
		final int PAGE_SIZE=12;
		keyword="%"+keyword+"%";
		
		return packPagedMap(pageNo,
				            PAGE_SIZE,
				            rptnMapper.countAlive(keyword),
				            rptnMapper.pagedQueryAlive(keyword,figureStart(pageNo,PAGE_SIZE), figureEnd(pageNo,PAGE_SIZE)));
	}
	
	@RequestMapping(value="/fetchEmps", method=RequestMethod.GET)
	public Map<String,Object> fetchEmps(int waitSeconds){
		try {
			Thread.sleep(waitSeconds*1000);
		}catch(Exception ex) {
			//
		}
		
		Map<String,Object> retvalMap=new LinkedHashMap<String,Object>();
		List<Emp> datas=new ArrayList<Emp>();
		datas.add(new Emp(1,"Andy",24));
		datas.add(new Emp(3,"Bill",34));
		datas.add(new Emp(4,"Cindy",44));
		datas.add(new Emp(5,"Douglas",54));
		datas.add(new Emp(9,"Eliot",64));
		
		retvalMap.put("datas", datas);
		
		return retvalMap;
	}
}
